<template>
	<view>
		<view class="data-box">
			<view class="form-block">
				<view class="card">
					<view class="card-body">
						<u--form
						class="from-card"
						labelPosition="left"
						labelWidth="100">
							<u-form-item label="项目名称" required borderBottom>
								<u--textarea
									disabled
									disabledColor="#ffffff"
									autoHeight
									border="none"
									v-model="info.projectName">
								</u--textarea>
							</u-form-item>
							<u-form-item label="成果名称" required borderBottom>
								<u--textarea
									disabled
									disabledColor="#ffffff"
									autoHeight
									border="none"
									v-model="info.fruitName">
								</u--textarea>
							</u-form-item>
							<u-form-item label="委托单位" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.firstCompany"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="甲方姓名" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.firstContacts"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="联系方式" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.firstPhone"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="测量开始时间" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.beginTime"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="测量结束时间" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.endTime"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="成果移交时间" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.time"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="项目负责人" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.fzrName"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item label="测量人员" required borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.clry"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<u-form-item
							label="情况说明"
							prop="remark"
							borderBottom>
								<u--textarea
								disabled
								disabledColor="#ffffff"
								v-model="info.remark"
								border="none"
								autoHeight >
								</u--textarea>
							</u-form-item>
							<u-form-item label="提交人" borderBottom>
								<u--input
								disabled
								disabledColor="#ffffff"
								v-model="info.createBy"
								inputAlign="right"
								border="none"
								></u--input>
							</u-form-item>
							<!-- <u-form-item v-if="info.status == 1" label="质检签名" required borderBottom>
								<u-upload
									:fileList="signImageList"
									:multiple="true"
									:maxCount="signImageList.length"
									:disabled="true"
									:deletable="false">
								</u-upload>
							</u-form-item> -->
						</u--form>
					</view>
				</view>
			</view>
		</view>
					
		<!-- <uni-group v-if="imageList.length>0">
			<u--form
			class="from-card"
			labelPosition="top"
			labelWidth="180">
				<u-form-item label="图片">
					<u-upload
						:fileList="imageList"
						:multiple="true"
						:maxCount="imageList.length"
						:disabled="true"
						:deletable="false">
					</u-upload>
				</u-form-item>
			</u--form>
		</uni-group> -->
		
		<!-- <view v-if="info.status == 0&&spType == '审批'">
			<u-button text="质检签名" type="primary" @click="gotoPage('/subPackTask/ountersign/sign')"></u-button>
			<view v-if='signImage' style='text-align: center;'>
				<image :src='signImage' style='width:200rpx;height:100rpx;' @click="showImage(signImage)"></image>
			</view>
		</view> -->
		
		<uni-section title="流程" type="line">
			<view class="per-list per-all">
				<view v-for="(item,index) in flowTaskList">
					<view class="list_user">
						<view class="left">
							<u-avatar
								v-if="item.avatar"
								:src="item.avatar"
								customStyle="width:100%;height:100%;"
								shape="square"
								size="35">
							</u-avatar>
							<u-avatar
								v-else
								customStyle="width:100%;height:100%;"
								:text="item.userName.slice(1)"
								bgColor="#0087FC"
								shape="square"
								size="35"
								:fontSize="item.userName.length > 2?12:15">
							</u-avatar>
							<view class="list_left_icon">
								<icon class="icon-box-img" type="waiting" size="15" color="#DD8E59" v-if="item.status == '0'"></icon>
								<icon class="icon-box-img" type="success" size="15" v-if="item.status == '1'"></icon>
								<icon class="icon-box-img" type="warn" size="15" v-if="item.status == '2'"></icon>
							</view>
						</view>
						<view class="right">
							<view class="line1" v-if="item.peopleType"><text>{{item.peopleType=='1'?'质检人':'审批人'}}</text><text v-if="item.status=='1'||item.status=='2'">{{item.updateTime}}</text></view>
							<view class="line1" v-else><text>{{index==0?'质检人':'审批人'}}</text><text v-if="item.status=='1'||item.status=='2'">{{item.updateTime}}</text></view>
							<view class="line2">
								<text>{{item.userName+(item.status == '2'?'(已拒绝)':'')}}</text>
							</view>
						</view>
					</view>
					<view class="list_user" v-if="item.status == '2'">
						<view class="left"></view>
						<view class="right">
							<!-- 拒绝理由 -->
							<view class="line3">
								<text>{{item.opinion}}</text>
							</view>
						</view>
					</view>

					<view class="list_line" v-if="index != flowTaskList.length-1"><view class="line"></view></view>
					<!-- <view class="list_line"><view class="lineDash"></view></view> -->
				</view>
				<view style="margin-top: 40rpx;" v-if="flowCsList && flowCsList.length > 0">
					<text>抄送人</text>
					<view class="per-list-csr" style="margin-top: 10rpx;">
						<view class="csr-item" v-for="(item,index) in flowCsList">
							<view class="pers-pic">
								<u-avatar
									v-if="item.avatar"
									:src="item.avatar"
									shape="square"
									size="35">
								</u-avatar>
								<u-avatar
									v-else
									:text="item.userName.slice(1)"
									bgColor="#0087FC"
									shape="square"
									size="35"
									:fontSize="item.userName.length > 2?12:15">
								</u-avatar>
								<view style="margin-top: 10rpx;">
									<text class="pers-name">{{item.userName}}</text>
								</view>
							</view>
							<view class="csr-icon" v-if="index != flowCsList.length-1">
								<u-icon name="plus" color="#cdcdcd" size="20rpx" bold></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-section>
		
		<view class="modifyList">
			<view class="titleBox">
				<view class="title">变更记录</view>
				<view class="addBGBtn" @click="bgjlFlag = true">新增变更</view>
			</view>
			<view class="bgjlInfo">
				<view class="bgjlItem" v-for="(item,index) in zxchFruitChangeRecordList">
					<view class="left">
						<u-avatar
							v-if="item.avatar"
							:src="item.avatar"
							customStyle="width:100%;height:100%;"
							shape="square"
							size="35">
						</u-avatar>
						<u-avatar
							v-else
							customStyle="width:100%;height:100%;"
							:text="item.reviser.slice(1)"
							bgColor="#0087FC"
							shape="square"
							size="35"
							:fontSize="item.reviser.length > 2?12:15">
						</u-avatar>
					</view>
					
					<view class="right">
						<view class="line1"><text class="username">{{item.reviser}}</text><text>{{item.dateTime}}</text></view>
						<view class="line2">
							<text>{{item.reason}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-show="bgjlFlag" class="bgjlLists">
			<view @click="bgjlFlag = false" class="shadow"></view>
			<view class="listInfo">
				<u--form
				class="from-card"
				labelWidth="80"
				:model="modifyInfo"
				:rules="rules"
				ref="ruleForm">
					<u-form-item
					label="修改人名称"
					prop="modifyUser"
					required
					@click="gotoPage('/components/choose-user/choosePer?chooseType=单选&chooseUsers='+JSON.stringify(modifyUserArr))"
					borderBottom>
						<u--input
						disabled
						disabledColor="#ffffff"
						suffixIcon="arrow-right"
						v-model="modifyInfo.modifyUser"
						placeholder="请选择修改人"
						inputAlign="right"
						border="none">
						</u--input>
					</u-form-item>
					<u-form-item
					label="情况说明"
					prop="remark"
					borderBottom>
						<u--textarea
						v-model="modifyInfo.remark"
						border="none"
						autoHeight
						count
						height="140"
						placeholder="请输入情况说明" >
						</u--textarea>
					</u-form-item>
				</u--form>
				
				<view class="bgjlBtn" @click="subModifyRecord()">提 交</view>
			</view>
		</view>
		
		<view class="submit-button" v-if="info.status == 0&&spType == '用户'">
			<view style="background-color: #9a9d9f;" class="submit-block" @click="submit()">
				撤 销
			</view>
		</view>
		<view class="submit-button" v-if="info.status == 0&&spType == '审批'">
			<view class="submit-block" v-if="user.userId == flowTaskList[0].userId">
				<view class="submit-block_item" @click="approve(1)">质检通过</view>
				<view class="submit-block_item" @click="approve(2)">未通过</view>
			</view>
			<view class="submit-block" v-else>
				<view class="submit-block_item" @click="approve(1)">同 意</view>
				<view class="submit-block_item" @click="approve(2)">拒 绝</view>
			</view>
		</view>
		
		<view class="qz">
			<span v-if="info.status == 1"><image src="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/49d884b6a24c4f9cb645b551a974dec3.png" /></span>
			<span v-if="info.status == 2"><image src="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/a2ef1372c79d42aeb3adec735fd6826e.png" /></span>
			<span v-if="info.status == 3"><image src="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/87530e13f0954b08b12f43b8998a6e14.pngg" /></span>
		</view>
		
	</view>
</template>

<script>
	import { getInfo,revoke,signImage,modifyRecord } from '@/api/fruit.js'
	import { uploadFile,removeByOssId } from '@/api/upload'
	export default {
		data() {
			return {
				user:{},
				spType:'用户',
				type:'',
				imageList:[],
				amountAll:0,
				info:{},
				expenseDetailList:[],
				flowTaskList:[],
				flowCsList:[],
				signImage: '',
				signImageList:[],
				imageResult:{},
				bgjlFlag:false,
				rules:{
					'modifyUser': {
						required: true,
						message: '请输入修改人名称',
						trigger: ['change']
					},
				},
				modifyInfo:{
					modifyUser:'',
					modifyId:'',
					remark:''
				},
				modifyUserArr:[{
					userName:'',
					userId:''
				}],
				zxchFruitChangeRecordList:[],
				czId:''
			}
		},
		onLoad(option) {
			this.user = uni.getStorageSync("loginInfo").user
			this.getDetail(option.id)
			this.spType = option.spType
			this.type = option.type
			this.czId = option.id
		},
		methods: {
			async uploadImage(e){
				const result = await uploadFile(e.url)
				this.imageResult = result
			},
			// 删除图片后事件
			async deletePic(e) {
				const result = await removeByOssId(e.ossId);
			},
			showImage(image){
				uni.previewImage({
					current: 0,     // 当前显示图片的索引值
					urls: [image],    // 需要预览的图片列表，photoList要求必须是数组
					loop:true,          // 是否可循环预览
				})
			},
			setSignImage(item){
				if(this.imageResult.ossId&&this.imageResult.ossId!=''){
					this.deletePic(this.imageResult)
				}
				this.signImage = item.signImage
				this.uploadImage({url:item.signImage})
			},
			async saveSignImage(){
				const { data } = await signImage({id:this.info.id,signImage:this.imageResult.url})
				if(data.code == 200){
					uni.navigateTo({
						url: '/subPackTask/work/cy/mysp/opinion?status=1&type='+this.type+'&tbId='+this.info.id+'&czId='+this.czId,
						events: {
							refreshPage: (data) => {
								this.$emit('refreshPage', data);
								// 触发传递给列表页的事件
								const eventChannel = this.getOpenerEventChannel();
            		eventChannel.emit('refreshPage', data);
							}
						}
					});
				}else{
					this.signImage = ''
					uni.showToast({
						title: '签名保存失败'
					})
				}
			},
			submit(){
				uni.showModal({
				  content: '确定要撤销申请吗？',
				  showCancel: true,
				  confirmText: '确定',
				  cancelText: '取消',
				  success: res => {
				    if (res.confirm) {
						this.doRevoke(this.info.id)
				    }
				  }
				})
			},
			async doRevoke(id){
				const { data } = await revoke(id);
				if(data.code == 200){
					uni.showToast({
						title: '撤销成功'
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 2
						});
					}, 500)
				}
			},
			async getDetail(id){
				const { data } = await getInfo(id);
				if(data.code == 200){
					this.info = data.data
					this.signImageList = [{url:this.info.signImage}]
					this.flowTaskList = data.data.flowTaskList
					this.flowCsList = data.data.flowCsVoList
					this.zxchFruitChangeRecordList = data.data.zxchFruitChangeRecordList
					// if(data.data.images!=''){
					// 	data.data.images.split(',').forEach(e=>{
					// 		this.imageList.push({url:e})
					// 	})
					// }
				}
			},
			approve(status){
				if(status == 1){
					// if(!this.signImage||this.signImage == ''){
					// 	uni.showToast({
					// 		title: '请质检签名'
					// 	})
					// 	return
					// }
					// 跳转到详情页
					uni.navigateTo({
						url: '/subPackTask/work/cy/mysp/opinion?status=1&type='+this.type+'&tbId='+this.info.id+'&czId='+this.czId,
						events: {
							refreshPage: (data) => {
								this.$emit('refreshPage', data);
								// 触发传递给列表页的事件
								const eventChannel = this.getOpenerEventChannel();
            		eventChannel.emit('refreshPage', data);
							}
						}
					});
				}else if(status == 2){
					uni.navigateTo({
						url: '/subPackTask/work/cy/mysp/opinion?status=2&type='+this.type+'&tbId='+this.info.id+'&czId='+this.czId,
						events: {
							refreshPage: (data) => {
								this.$emit('refreshPage', data);
								// 触发传递给列表页的事件
								const eventChannel = this.getOpenerEventChannel();
            		eventChannel.emit('refreshPage', data);
							}
						}
					});
				}
			},
			setChooseUser(e){
				this.modifyInfo.modifyUser = this.modifyUserArr[0].userName = e[0].userName
				this.modifyInfo.modifyId = this.modifyUserArr[0].userId = e[0].userId
			},
			subModifyRecord() {
				let arr = {
					id:this.info.id,
					zxchFruitChangeRecord:{
						infoId:this.info.id,
						reviser:this.modifyInfo.modifyUser,
						userId:this.modifyInfo.modifyId,
						reason:this.modifyInfo.remark,
						dateTime:this.formatDate(new Date())
					}
				}
				modifyRecord(arr).then(res=> {
					if(res.statusCode === 200) {
						uni.showToast({
							title: '变更记录添加成功'
						})
						this.bgjlFlag = false
						this.getDetail(this.info.id)
					}
				})
			},
			formatDate(newDate) {
			    let date = newDate;
			    let YY = date.getFullYear();
			    let MM = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
			    let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
			    let hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
			    let mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
			    let ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				return  YY + "-" + MM + "-" + DD +' '+ hh + ":" + mm
			},
		}
	}
</script>

<style>
.per-list.per-all {
	padding: 30rpx;
}
.list_user {
	display: flex;
	justify-content: space-between;
	margin-bottom: 10rpx;
}
.list_user .left {
	position: relative;
	width: 10%;
	font-size: 1em !important;
}
.list_left_icon {
	position: absolute;
	bottom: 0;
	right: 0;
}
.list_user .right {
	width: 85%;
}
.list_user .right .line1 {
	display: flex;
	justify-content: space-between;
	color: #999;
}
.list_user .right .line2 {
	color: #666;
}
.list_user .right .line3 {
	padding: 10rpx;
	background-color: #d4d4d4;
	border-radius: 0 10rpx 10rpx 10rpx;
	line-height: 2;
	color: #666;
	font-size: 25rpx;
}
.list_line {
	width: 10%;
	text-align: center;
}
.list_line .line {
	display: inline-block;
	vertical-align: middle;
	height: 60rpx;
	border-left: 6rpx solid #aaa;
	border-radius: 5rpx;
}
.list_line .lineDash {
	display: inline-block;
	vertical-align: middle;
	height: 60rpx;
	border-left: 6rpx dashed #aaa;
	border-radius: 5rpx;
}

	.per-list {
		margin-right: 50rpx;
	}
	
	.pers-pic {
		height: 65rpx;
	}
	
	.pers-name {
		color: #a5a5a5;
		font-size: 25rpx;
		width: 50rpx;
	}
	
	.pers-icon {
		position: relative;
		top: -80rpx;
		left: 85rpx;
		width: 26rpx;
	}
	
	.card-plus-t {
		display: flex;
		/* flex-direction: row-reverse; */
		/* justify-content: right; */
		text-align: center;
	}
	.submit-block_item {
		box-sizing: border-box;
		vertical-align: middle;
		display: inline-block;
		width: 50%;
		background-color: #0087FC;
	}
	.submit-block_item:nth-child(1) {
		border-right: 2rpx solid #fff;
	}
	.submit-block_item:nth-child(2) {
		background-color: #9a9d9f;
	}
	.per-list-csr {
		display: flex;
		justify-content: left;
	}
	.per-list-csr .csr-item {
		text-align: center;
		display: flex;
	}
	.csr-item .csr-icon  {
		display: flex;
		margin: 0 10rpx;
	}
	
	.qz {
	  position: absolute;
	  right: 80rpx;
	  top: 40rpx;
	}
	.qz image {
	  width: 150rpx;
	  height: 150rpx;
	}
	.list_left_icon {
		background-color: #fff;
		border-radius: 50%;
	}
	.list_left_icon icon{
		vertical-align: bottom;
		display: block;
	}
	.submit-button .submit-block {
		background-color: #fff;
	}
	
	.caozuo1 {
		display: flex;
		height: 0;
		height: constant(safe-area-inset-bottom);  
		height: env(safe-area-inset-bottom);
		width: 750upx;
		position: fixed;
		left: 0;
		bottom: 0;
		background-color: #0599D7;
	
	}
	.caozuo {
		display: flex;
		height: 100rpx;
		width: 100%;
		margin-top:20rpx;
		font-size: 28rpx;
		
	}
	.caozuo view {
		width: 40%;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		margin-left:5%;
		border-radius: 40rpx;
	}
	.caozuo view:last-child {
		width: 40%;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		margin-left:10%;
	}
	
	.caozuo view:active {
		background-color: #CCCCCC;
		color: #333333;
	}
	
	.chongqian {
		background-color: #FF8F58;
	}
	
	.over {
		background-color: #0599D7;
	}
</style>

<style>
	page {
		padding-bottom: 30rpx;
	}
	.modifyList {
		margin-top: 30rpx;
	}
	.modifyList .titleBox {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}
	.modifyList .title {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 24rpx;
		font-weight: normal;
		font-size: 28rpx;
		color: #333;
	}
	.addBGBtn {
		padding: 20rpx 24rpx;
		margin-right: 30rpx;
		text-align: center;
		background: #0087FC;
		border-radius: 10rpx;
		color: #fff;
		font-size: 28rpx;
	}
	.modifyList .title::before {
		content: '';
		display: inline-block;
		width: 8rpx;
		height: 24rpx;
		border-radius: 20rpx;
		background-color: #2979ff;
		margin-right: 12rpx;
	}
	.bgjlItem {
		display: flex;
		margin-bottom: 20rpx;
	}
	.modifyList .bgjlInfo {
		padding: 0 30rpx;
		margin-right: 50rpx;
	}
	.modifyList .bgjlItem .left {
		position: relative;
		width: 10%;
		height: 10%;
		aspect-ratio: 1/1;
		font-size: 1em !important;
		margin-right: 30rpx;
	}
	.modifyList .bgjlItem .right {
		width: 85%;
	}
	.modifyList .bgjlItem .right .line1 {
		display: flex;
		justify-content: space-between;
		color: #999;
		font-size: 24rpx;
		margin-bottom: 14rpx;
	}
	.modifyList .bgjlItem .right .line1 .username {
		color:#333;
	}
	.bgjlLists {
		z-index: 99;
	}
	.bgjlLists .shadow {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, .5);
	}
	.listInfo {
		box-sizing: border-box;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		height: 40vh;
		background-color: #fff;
		padding: 30rpx;
		z-index: 99;
	}
	.bgjlBtn {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100vw;
		line-height: 100rpx;
		text-align: center;
		background-color: #0087FC;
		color: #fff;
	}
</style>